#Author:Jason Song
import json
with open('D:/游戏/JX3/Game/JX3/bin/zhcn_hd/interface/MY#DATA/306244774680172488@zhcn/userdata/fight_stat/2021-04-09-19-14-20_高级试炼木桩_11.fstt.jx3dat', mode='rb') as d:
    content = d.read()
    a = content.decode("gb2312")[7:].strip('{').strip('}')
    # print(a)
    lis = []
    k = ''
    count = 0
    for i in a:
        if i ==  "{":
            count += 1
        elif i == "}":
            count -= 1
        if i != ",":
                k = k + i
        else:
            if count == 0:
                lis.append(k)
                k = ''
            else:
                k = k + i
    dic = {}
    for i in lis :
        print(i)
        try:
            if i[1] == '4' and i[2] == ']':
                dic["timestamp"] = i[4:]
            elif i[1] == '1' and i[2] == '9':
                dic["district"] = i[5:]
            elif i[1] == '9' and i[2] == ']':
                dic["target"] = eval(i[4:].replace('=',":").replace('[','').replace(']',''))
            elif i[1] == '1' and i[2] == '1':
                dic["skills"] = i[5:].replace('=',":").replace('[','').replace(']','')
                string = list(dic["skills"])
                for m in range(0,len(string)-1):
                    if 0 < m < len(string)-1:
                        if string[m] == '{':
                            string[m] = '['
                        elif string[m] == '}':
                            string[m] = ']'
                dic["skills"] = json.loads(''.join(string))
            elif i[1] == '1' and i[2] == '6':
                dic["record"] = i[6:-1]
                list_lis = []
                list_k = ''
                list_count = 0
                for list_i in dic["record"]:
                    if list_i ==  "{":
                        list_count += 1
                    elif list_i == "}":
                        list_count -= 1
                    if list_i != ",":
                            list_k = list_k + list_i
                    else:
                        if list_count == 0:
                            list_lis_str = list_k[1:-1]
                            str_string = list(list_lis_str)

                            str_lis = []
                            str_k = ''
                            str_count = 0
                            str_num = 0
                            for str_i in str_string:
                                if str_i ==  "{":
                                    str_count += 1
                                elif str_i == "}":
                                    str_count -= 1
                                elif str_i == "\"":
                                    if str_num == 0:
                                        str_count += 1
                                        str_num += 1
                                    elif str_num != 0:
                                        str_count -= 1
                                        str_num -= 1
                                if str_i != ",":
                                        str_k = str_k + str_i
                                else:
                                    if str_count == 0:
                                        str_lis.append(str_k)
                                        str_k = ''
                                    else:
                                        str_k = str_k + str_i
                            # print(str_lis)
                            list_lis.append(str_lis)
                            list_k = ''
                        else:
                            list_k = list_k + list_i
                # print(list_lis)
                dic["record"] = list_lis
        except Exception as e:
            print(e)
    print(dic["record"])
    # 处理战斗记录
    for i in dic["record"]:
        # if i[3] in ['1','5','6']:
        print(i)





